﻿#include "ConfigData.h"

#define defLoadIntFromJson(obj,var) obj.var=jsonObj[#var].toInt()
#define defLoadBoolFromJson(obj,var) obj.var=jsonObj[#var].toBool()
#define defLoadFloatFromJson(obj,var) obj.var=jsonObj[#var].toDouble()

#define defSaveDataToJson(obj,var) jsonObj[#var]=obj.var

#define defEncodeParam(var) encodeParam(var,json[#var])
#define defParseParam(var) parseParam(var,json[#var])

ConfigData::ConfigData()
{

}

ConfigData::~ConfigData()
{

}

QJsonObject ConfigData::toJsonObject() const
{
	QJsonObject json;
	encodeParam(paramHardware, json["paramHardware"]);
	json["xmlPath"] = xmlPath;
	return json;
}

void ConfigData::fromJsonObject(const QJsonObject& json)
{
	parseParam(paramHardware, json["paramHardware"]);
	xmlPath = json["xmlPath"].toString();
}

//void ConfigData::onBuildStructure() const
//{
//	DECLARE_SUB_STRUCTURE(paramHardware,)
//}

void parseParam(ConfigParams& param, const QJsonValue& value)
{
	QJsonObject jsonObj = value.toObject();
	defLoadFloatFromJson(param, expandValue);
	defLoadIntFromJson(param, imgAccount);
	defLoadIntFromJson(param, processWay);
	defLoadFloatFromJson(param, rowFrequency);
	defLoadFloatFromJson(param, colFrequency);
}

void encodeParam(const ConfigParams& param, QJsonValueRef value)
{
	QJsonObject jsonObj;
	defSaveDataToJson(param, expandValue);
	defSaveDataToJson(param, imgAccount);
	defSaveDataToJson(param, processWay);
	defSaveDataToJson(param, rowFrequency);
	defSaveDataToJson(param, colFrequency);
	value = jsonObj;
}
